/**
 * Created by Weilin Shi on 2015/7/15.
 */
/*global angular, probe*/
probe.filter("postProcess", function () {
	"use strict";
	var types = "DelayStep EventStep";
	var typeMap = types.split(" ");
	var actions = "click input dblclick rclick movein moveout scroll";
	var actMap = actions.split(" ");
	return function (input) {
		var body = {};

		body.process = {
			name: input.name(),
			comment: input.comment(),
			loops: input.loops(),
			config: (function () {
				var config = {};
				config.origin = input.origin();
				return angular.toJson(config);
			}()),
			id: input.id()
		};

		body.steps = (function () {
			var steps = [];

			angular.forEach(input.program(), function (step, index) {
				var json = step.getOptions();
				json.stepId = json.id;
				json.order = index;
				json.type = typeMap.indexOf(json.type);
				json.actionParam = angular.toJson(json.param);
				json.typeParam = angular.toJson(json.typeParam);
				json.action = actMap.indexOf(json.action);
				delete json.createtime;
				delete json.updatetime;
				delete json.id;
				delete json.param;
				steps.push(json);
			}, steps);

			return steps;
		}());

		if (input.hasDictionary()) {
			body.process.dictionaryId = input.dictionary().id();
		}

		return body;
	};
});
